]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
introspect: Make invocation check error-based
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 2 Sep 2021 14:23:38 +0000 (16:23 +0200)
committerMarge Bot <marge-bot@gnome.org>
Fri, 3 Sep 2021 21:34:58 +0000 (21:34 +0000)
If we throw an error when the invocation isn't allowed instead of
returning false, we can simply return that error instead of duplicating
the error handling.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1970>

js/misc/introspect.js

index 85f491a693b0e59009d8783af527dc886c8961fd..3cb021cb1f7e2891702bd194f2e33edcde562a7e 100644 (file)
@@ -137,21 +137,23 @@ var IntrospectService = class {
                 type == Meta.WindowType.UTILITY;
     }
 
-    _isInvocationAllowed(invocation) {
+    _checkInvocation(invocation) {
         if (this._isIntrospectEnabled())
-            return true;
+            return;
 
         if (this._isSenderAllowed(invocation.get_sender()))
-            return true;
+            return;
 
-        return false;
+        throw new GLib.Error(Gio.DBusError,
+            Gio.DBusError.ACCESS_DENIED,
+            'App introspection not allowed');
     }
 
     GetRunningApplicationsAsync(params, invocation) {
-        if (!this._isInvocationAllowed(invocation)) {
-            invocation.return_error_literal(Gio.DBusError,
-                                            Gio.DBusError.ACCESS_DENIED,
-                                            'App introspection not allowed');
+        try {
+            this._checkInvocation(invocation);
+        } catch (e) {
+            invocation.return_gerror(e);
             return;
         }
 
@@ -163,10 +165,10 @@ var IntrospectService = class {
         let apps = this._appSystem.get_running();
         let windowsList = {};
 
-        if (!this._isInvocationAllowed(invocation)) {
-            invocation.return_error_literal(Gio.DBusError,
-                                            Gio.DBusError.ACCESS_DENIED,
-                                            'App introspection not allowed');
+        try {
+            this._checkInvocation(invocation);
+        } catch (e) {
+            invocation.return_gerror(e);
             return;
         }